package com.dailyblue.project.smbms.alibaba.goods.controller;

import com.dailyblue.project.smbms.alibaba.commons.util.JsonResult;
import com.dailyblue.project.smbms.alibaba.commons.util.ResultTool;
import com.dailyblue.project.smbms.alibaba.goods.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @GetMapping
    public JsonResult find() {
        return goodsService.findAllGoods();
    }

    @GetMapping("/addcart")
    public JsonResult addCart(int id, HttpServletRequest request) {
        return goodsService.addCart(request, id);
    }

    @GetMapping("/show")
    public JsonResult showCart(HttpServletRequest request) {
        return goodsService.showCart(request);
    }

    @GetMapping("/remove")
    public JsonResult removeCart(HttpServletRequest request, int goodsId) {
        return goodsService.removeCart(request, goodsId);
    }

    @GetMapping("/update/{goodsId}/{newNum}")
    public JsonResult updateCart(HttpServletRequest request, @PathVariable("goodsId") int goodsId, @PathVariable("newNum") int newNum) {
        return goodsService.updateCart(request, goodsId, newNum);
    }
}
